package com.wyy.reflect;

import java.lang.reflect.Field;

public class TestReflectField2 {
	//通过反射机制操作某个类的属性
    private String proprety = null;
    public static void main(String[] args) throws Exception {
        Class<?> clazz = Class.forName("com.wyy.reflect.TestReflectField2");
        Object obj = clazz.newInstance();
        // 可以直接对 private 的属性赋值
        Field field = clazz.getDeclaredField("proprety");
        field.setAccessible(true);
        field.set(obj, "Java反射机制");
        System.out.println(field.get(obj));
        //Java反射机制
    }
}
